//
//  KWeiHomeController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 2017/5/24.
//  Copyright © 2017年 EasyToTesco. All rights reserved.
//

#import "KWeiHomeController.h"
#import "CustNaviBarView.h"

#import "kWMenuCell.h"
#import "kWCommonHeadView.h"
#import "kW3dcycleCell.h"
#import "kWGoodCell.h"
#import "kWFixedCell.h"
#import "kWTailorCell.h"
#import "kWSimpleCell.h"
#import "kWFixed4Cell.h"

#import "kWListsCell.h"
#import "kWLikeCell.h"

#import "RecommendedController.h"
#import "OilRechargeController.h"
#import "RechargeController.h"
#import "BusinessTableViewController.h"

#import "ProductSearchViewController.h"
#import "LocationServeViewController.h"
#import "ReadWriteLocationCity.h"
#import "LocationServeManager.h"
#import "ShopDetailsController.h"
#import "EasyToTescoNewsDetailsVc.h"
#import "BusinessDetailsController.h"
#import "AdBussinessController.h"

#import "kWHomeModel.h"
#import "kWCommonModel.h"

static NSString * const kWei_Home_menu           = @"kWei_Home_menuIdentifier";
static NSString * const kWei_Home_header         = @"kWei_Home_headerIdentifier";

static NSString * const kWei_Home_3dCycle        = @"today_selling";
static NSString * const kWei_Home_fixed          = @"customization";
static NSString * const kWei_Home_Like           = @"new_product";
static NSString * const kWei_Home_tailor         = @"personal_tailor";
static NSString * const kWei_Home_simple         = @"simple_fashion";
static NSString * const kWei_Home_fixed4         = @"living_experience";
static NSString * const kWei_Home_Good           = @"guess_like";


@interface KWeiHomeController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,CLLocationManagerDelegate,SDCycleScrollViewDelegate>
{
    BOOL          _JudgeFirstLocationCity;
    NSString      *_cityString;
    NSDictionary  *_oilCardDictionary;
    NSInteger     _refreshIndex;
}


@property(nonatomic,strong)SDCycleScrollView  *cycleScrollView;
@property(nonatomic,strong)UITableView        *tableView;
@property(nonatomic,strong)CustNaviBarView    *naviBarView;

//数据数组
@property(nonatomic,strong) NSMutableArray <kWHomeModel *>   *bannerArray;
@property(nonatomic,strong) NSMutableArray <kWCommonModel*>  *contentArray;
//猜你喜欢
@property(nonatomic,strong) NSMutableArray <kWHomeModel *>   *likeArray;

@end

@implementation KWeiHomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    _refreshIndex = 0;
    [self loadkWeiHomeData];
    [self addRefreshView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netWorkConnectLoseView) name:NOTIFICATION_netWork_error object:nil];
    
    [self showLoadingView];
    
    //版本
    [self judgeAppVersion];
}

- (void)buildHomeView
{
    self.title = @"首页";
    [self.view addSubview:self.tableView];
    
    _JudgeFirstLocationCity = true;
    self.automaticallyAdjustsScrollViewInsets = false;
    
    [LocationServeManager sharedLocationServeManager].delegate = self;
  
    [self.tableView registerClass:[kWMenuCell class] forCellReuseIdentifier:kWei_Home_menu];
    [self.tableView registerClass:[kWCommonHeadView class] forHeaderFooterViewReuseIdentifier:kWei_Home_header];
    [self.tableView registerClass:[kW3dcycleCell class] forCellReuseIdentifier:kWei_Home_3dCycle];
    [self.tableView registerClass:[kWGoodCell class] forCellReuseIdentifier:kWei_Home_Good];
    [self.tableView registerClass:[kWFixedCell class] forCellReuseIdentifier:kWei_Home_fixed];
    [self.tableView registerClass:[kWTailorCell class] forCellReuseIdentifier:kWei_Home_tailor];
    [self.tableView registerClass:[kWSimpleCell class] forCellReuseIdentifier:kWei_Home_simple];
    [self.tableView registerClass:[kWLikeCell class] forCellReuseIdentifier:kWei_Home_Like];
    [self.tableView registerClass:[kWFixed4Cell class] forCellReuseIdentifier:kWei_Home_fixed4];
    
    self.tableView.contentInset = UIEdgeInsetsMake(0,0,48,0);
    [self.view addSubview:self.naviBarView];
}

- (void)addRefreshView
{
    //上啦
    self.tableView.mj_footer = [TopPullRefreshAnaimation footerWithRefreshingTarget:self refreshingAction:@selector(loadkWeiMoreData)];
    
    //下拉
    self.tableView.mj_header = [MJChiBaoZiHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadkWeiHomeData)];

}

- (void)netWorkConnectLoseView
{
    
    UIImageView *loseImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noNetwork"]];
    [self.view addSubview:loseImg];
    WeakSelf(self);
    [loseImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakself.view.mas_centerX);
        make.centerY.equalTo(weakself.view.mas_centerY).offset(-HEIGHT/8);
        make.width.mas_equalTo(WIDTH/2);
        make.height.mas_equalTo(HEIGHT/4);
    }];
    
    UIButton *error = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:error];
    [error setTitle:@"重新加载" forState:UIControlStateNormal];
    [error setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [error setBackgroundColor:DEFAULT_COLOR];
    error.titleLabel.font = BOLDFONT(16);
    error.layer.masksToBounds = true;
    error.layer.cornerRadius = 3;
    @weakify(self);
    [[error rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        @strongify(self); [self loadkWeiHomeData];
    }];
    [error mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakself.view.mas_centerX);
        make.top.equalTo(loseImg.mas_bottom).offset(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(35);
    }];
}

#pragma mark - scrollView delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat y = scrollView.contentOffset.y;
    if(y <= 0){
        _naviBarView.alpha = 1;//往上滑动
        _naviBarView.backgroundColor = [UIColor clearColor];
        _naviBarView.searchStr = @"kW_home_search";
        if (y<0) {
            _naviBarView.hidden = true;
        }else{
            _naviBarView.hidden = false;
        }
    }else{
        [UIView animateWithDuration:0.2f animations:^{
            _naviBarView.backgroundColor = DEFAULT_COLOR;
        }];
        _naviBarView.hidden = false;
        _naviBarView.alpha = (y)/100;
        _naviBarView.searchStr = @"kW_home_searchOffset";
    }
}


#pragma mark  network
- (void)loadUserInfoData {
    if (!USERNAME) {
        return;
    }
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:@{@"username":USERNAME} AndMenthodName:@"api/User/info" completeBlock:^(id object) {
            _oilCardDictionary = object[@"data"];
        }] ;
    });
}

- (void)loadkWeiHomeData
{
    @weakify(self);
    NSDictionary *param = @{@"app_type":@"ios"};
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:param AndMenthodName:@"api/home/getdataforappindex" completeBlock:^(id object) {
        @strongify(self);
        if (JudgeBackDataCode) {
            
//            NSLog(@"%@",object);
            
            NSDictionary *dataDict = [object objectForKey:@"data"];
            self.bannerArray= [kWHomeModel arrayOfModelsFromDictionaries:[dataDict objectForKey:@"banner"] error:nil];
            self.contentArray = [kWCommonModel arrayOfModelsFromDictionaries:[dataDict objectForKey:@"content"] error:nil];
            
            kWCommonModel *model = self.contentArray.lastObject;//猜你喜欢
            for (NSDictionary *homeModel in model.data) { // homeModel 字典转模型
                kWHomeModel *home = [[kWHomeModel alloc] initWithDictionary:homeModel error:nil];
                [self.likeArray addObject:home];
            }

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                 [self buildHomeView];
            });
            
        }else{
            //gg 重新刷新
            [self netWorkConnectLoseView];
            
        }
    }];
    
    [self.tableView reloadData];
    [self.tableView.mj_header endRefreshing];
    [self hideLoadingView];
}

- (void)loadkWeiMoreData
{
    _refreshIndex ++;
    
    NSDictionary *params = @{@"p":@(_refreshIndex)};
    @weakify(self); NSLog(@"%@",params);
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"api/home/getguesslikedataforandroid" completeBlock:^(id object) {
        @strongify(self);
        if (JudgeBackDataCode) {
            NSDictionary *dataDict = [object objectForKey:@"data"];
            NSArray *data = [dataDict objectForKey:@"content"];
            for (NSDictionary *dict in data) {
                kWHomeModel *model = [[kWHomeModel alloc] initWithDictionary:dict error:nil];
                [self.likeArray addObject:model];
            }
        }else{
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }
        [self.tableView reloadData];
    }];
    
    [self.tableView.mj_footer endRefreshing];
}



#pragma mark tableView datasource delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 8;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 7:
            return self.likeArray.count > 0 ? self.likeArray.count:0;
            break;
            
        default:
            return 1;
            break;
    };
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.section) {
        case 0:
        {
            kWMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_menu forIndexPath:indexPath];
            WeakSelf(self);
            [cell setMenuBlock:^(kWMenuClikcType type) {
                [weakself menuClick:type];
            }];
            return cell;
        }
            break;
        case 1:
        {
            kW3dcycleCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_3dCycle forIndexPath:indexPath];
            WeakSelf(self);
            [cell setThreeDBlock:^(kWHomeModel *homeModel) {
                [weakself kWBannerClickType:[homeModel.type integerValue] value:homeModel.value title:homeModel.title];
            }];
            kWCommonModel *model = self.contentArray[indexPath.section -1];
            cell.data = model.data;
            return cell;
        }
            break;
            
        case 2:
        {
            kWFixedCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_fixed forIndexPath:indexPath];
            WeakSelf(self);
            [cell setFixedBlock:^(kWHomeModel *homeModel) {
                [weakself kWBannerClickType:[homeModel.type integerValue] value:homeModel.value title:homeModel.title];
            }];
            
            kWCommonModel *model = self.contentArray[indexPath.section -1];
            cell.data = model.data;

            return cell;

        }
            break;
            
        case 3:
        {
            kWLikeCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_Like forIndexPath:indexPath];
            WeakSelf(self);
            [cell setLikeBlock:^(kWHomeModel *homeModel) {
                [weakself kWBannerClickType:[homeModel.type integerValue] value:homeModel.value title:homeModel.title];
            }];
            
            kWCommonModel *model = self.contentArray[indexPath.section -1];
            cell.data = model.data;
            return cell;

        }
            break;
            
        case 4:
        {
            kWTailorCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_tailor forIndexPath:indexPath];
            WeakSelf(self);
            [cell setTailorBlock:^(kWHomeModel *homeModel) {
                [weakself kWBannerClickType:[homeModel.type integerValue] value:homeModel.value title:homeModel.title];
            }];
            
            kWCommonModel *model = self.contentArray[indexPath.section -1];
            cell.data = model.data;
            return cell;
        }
            break;
            
        case 5:
        {
            kWSimpleCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_simple forIndexPath:indexPath];
            WeakSelf(self);
            [cell setSimpleBlock:^(kWHomeModel *homeModel) {
                [weakself kWBannerClickType:[homeModel.type integerValue]value:homeModel.value title:homeModel.title];
            }];
            kWCommonModel *model = self.contentArray[indexPath.section -1];
            cell.data = model.data;
            return cell;
        }
            break;
            
        case 6:
        {
            kWFixed4Cell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_fixed4 forIndexPath:indexPath];
            WeakSelf(self);
            [cell setFixed4Block:^(kWHomeModel *homeModel) {
               [weakself kWBannerClickType:[homeModel.type integerValue]value:homeModel.value title:homeModel.title];
            }];
            
            kWCommonModel *model = self.contentArray[indexPath.section -1];
            cell.data = model.data;
            return cell;
        }
            break;
       
        default:
        {
            kWGoodCell *cell = [tableView dequeueReusableCellWithIdentifier:kWei_Home_Good forIndexPath:indexPath];
            cell.homeModel = self.likeArray[indexPath.row];
            WeakSelf(self);
            [cell setLikeBlock:^{
                ShopDetailsController *detailsVC = [[ShopDetailsController alloc] init];
                kWHomeModel *homeModel = weakself.likeArray[indexPath.row];
                detailsVC.goodsId = homeModel.value;
                detailsVC.title = homeModel.title;
                [weakself.navigationController pushForm:weakself.navigationController pushToAndHidden:detailsVC];
            }];
            
            return cell;
        }
            break;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 7) {
        ShopDetailsController *detailsVC = [[ShopDetailsController alloc] init];
        kWHomeModel *homeModel = self.likeArray[indexPath.row];
        detailsVC.goodsId = homeModel.value;
        detailsVC.title = homeModel.title;
        [self.navigationController pushForm:self.navigationController pushToAndHidden:detailsVC];
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            return 85;//menu
            break;
        case 1:
            return HEIGHT*0.35; //3d
            break;
        case 2:
            return HEIGHT*0.25+10; //fixed
            break;
        case 3:
            return HEIGHT*0.21; //like
            break;
        case 4:
            return HEIGHT*0.4+10; //tailor
            break;
        case 5:
            return HEIGHT*0.21; //simple
            break;
        case 6:
            return HEIGHT*0.25+10; //fixed4
            break;
        default:
            return HEIGHT*0.41;//goods
            break;
    }
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        NSMutableArray *imageArr = [NSMutableArray array];
        for (kWHomeModel *adModel in self.bannerArray) {
            [imageArr addObject:adModel.img];
        }
        self.cycleScrollView.imageURLStringsGroup = imageArr;
        return self.cycleScrollView;
    }else{
        kWCommonHeadView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kWei_Home_header];
        if (self.contentArray.count==7) {//保险
            kWCommonModel *commonModel = self.contentArray[section - 1];
            header.text = commonModel.title;
        }
        return header;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    switch (section) {
        case 0:
            return HEIGHT*0.3;
            break;
        default:
            return 44;
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 8;
}


#pragma mark banner delegate
/** 点击轮播图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (self.bannerArray.count > 0) {
        kWHomeModel *model = self.bannerArray[index];
        [self kWBannerClickType:[model.type integerValue] value:model.value title:model.title];
    }
}

/** 点击banner  type  */
- (void)kWBannerClickType:(NSInteger)type value:(NSString *)value title:(NSString *)title
{
    switch (type) {
        case 1:
            //商品
        {
            ShopDetailsController *detailsVC = [[ShopDetailsController alloc] init];
            detailsVC.goodsId = value;
            detailsVC.title = title;
            [self.navigationController pushForm:self.navigationController pushToAndHidden:detailsVC];
            break;
            
        }
            
        case 2:
            //商品列表
        {
            RecommendedController*recommendedVC = [[RecommendedController alloc] init];
            recommendedVC.product_id = value;
            recommendedVC.title = title;
            recommendedVC.is_actPush = YES;
            [self.navigationController pushForm:self.navigationController pushToAndHidden:recommendedVC];
            break;
        }
            
        case 3:
            //文章
        {
            EasyToTescoNewsDetailsVc *newsDetailsVC = [[EasyToTescoNewsDetailsVc alloc] init];
            newsDetailsVC.link = value;
            newsDetailsVC.title = title;
            [self.navigationController pushForm:self.navigationController pushToAndHidden:newsDetailsVC];
            break;
        }
            
        case 4:
            //店铺
        {
            BusinessDetailsController *detailVC = [[BusinessDetailsController alloc] init];
            detailVC.bussinessId = value;
            [self.navigationController pushForm:self.navigationController pushToAndHidden:detailVC];
            break;
        }
            
        case 5:
            //店铺列表
        {
            AdBussinessController *AdBussinessVC = [[AdBussinessController alloc] init];
            AdBussinessVC.value = value;
            AdBussinessVC.title = title;
            [self.navigationController pushForm:self.navigationController pushToAndHidden:AdBussinessVC];
            break;
        }
        default:
            break;
    }
}

#pragma mark menu push method
- (void)menuClick:(kWMenuClikcType)type
{
    switch (type) {
        case kWMenuClikcTypeHot:
        {
            RecommendedController*recommendedVC = [[RecommendedController alloc] init];
            recommendedVC.title = @"精品推荐";
            [self.navigationController pushForm:self.navigationController pushToAndHidden:recommendedVC];

        }break;
            
        case kWMenuClikcTypeBussiness:
        {
            BusinessTableViewController *bussinessVC = [[BusinessTableViewController alloc] init];
            bussinessVC.title = @"优秀商家";
            bussinessVC.HOME_PUSH_Business = true;
            [self.navigationController pushForm:self.navigationController pushToAndHidden:bussinessVC];
            
        }break;
            
        case kWMenuClikcTypeTelephone:
        {
            RechargeController *rechargeVC = [[RechargeController alloc] init];
            rechargeVC.title = @"话费充值";
            [self.navigationController pushForm:self.navigationController pushToAndHidden:rechargeVC];
        }break;
            
        default:
        {
            OilRechargeController*oilVC = [[OilRechargeController alloc] init];
            oilVC.title = @"油卡充值";
            oilVC.oilNumberString = _oilCardDictionary[@"youka"];
            [self.navigationController pushForm:self.navigationController pushToAndHidden:oilVC];
            
        }break;
    }
}

#pragma mark - CLLocationManangerDelegate
//定位成功以后调用
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    
    [[LocationServeManager sharedLocationServeManager] stop];
    CLLocation* location = locations.lastObject;
    [self reverseGeocoder:location];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"%s",__func__);
}

//反地理编码
- (void)reverseGeocoder:(CLLocation *)currentLocation {
    
    if (!_JudgeFirstLocationCity) {
        return;
    }
    
    CLGeocoder* geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if(error || placemarks.count == 0){
            //            NSLog(@"error = %@",error);
        }else{
            CLPlacemark* placemark = placemarks.firstObject;
            
            NSString *appCityString = [NSString stringWithFormat:@"%@",[ReadWriteLocationCity ReadLocatinoCity]];
            
            NSLog(@"%@",[[placemark addressDictionary] objectForKey:@"City"]);
            
            NSString *string = [[placemark addressDictionary] objectForKey:@"City"];
            NSInteger length = string.length;
            _cityString = [string substringWithRange:NSMakeRange(0, length - 1)];
            
            [ReadWriteLocationCity saveLocationString:_cityString];
            
            NSLog(@"%@-------%@",appCityString,_cityString);
            if ([appCityString isEqualToString:_cityString]) {
                return;
            }
            
            NSString *TitleString = [NSString stringWithFormat:@"检测到您当前位置为:%@",[[placemark addressDictionary] objectForKey:@"City"]];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:TitleString message:@"是否切换城市" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            alert.tag = 100101;
            [alert show];
        }
    }];
    _JudgeFirstLocationCity = NO;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 100101) {
        if (buttonIndex == 1) {
            NSLog(@"%@",_cityString);
            [ReadWriteLocationCity saveLocationCity:_cityString];
            self.naviBarView.locationStr = _cityString;
        }
    }
}

//https://itunes.apple.com/cn/app/%E5%8F%AF%E4%B8%BA%E5%BB%BA%E6%9D%90%E8%81%94%E7%9B%9F/id1244680543?mt=8
- (void)judgeAppVersion {
    
    NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString* versionNum = [infoDict objectForKey:@"CFBundleShortVersionString"];
    //    NSLog(@"xcode : --- %@",versionNum);
    
    [[NetWorkSharedTools sharedNetWorkTools] GetObjectWithURLDict:@{@"version":versionNum,@"type":@"1"} AndMenthodName:@"api/version/checkVersion" completeBlock:^(id object) {
        
        if (!JudgeBackDataCode) {

            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"尊敬的用户您好:为了更好的使用和体验可为建材联盟还请您及时更新App!" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *update = [UIAlertAction actionWithTitle:@"立即去更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/cn/app/%E5%A4%A7%E6%9C%89%E5%8F%AF%E4%B8%BA/id1244680543?mt=8"];
                [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
            }];
            
            [alert addAction:update];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}




#pragma mark view 周期
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:true animated:animated];
    
    
    NSString *locationCityString = [ReadWriteLocationCity ReadLocatinoCity];
    if (locationCityString.length) {
        self.naviBarView.locationStr = locationCityString;
    } else {
        self.naviBarView.locationStr = @"定位";
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:false animated:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark lazy
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,WIDTH,HEIGHT) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        //        _tableView.backgroundColor = BACKGROUND_COLOR;
    }
    return _tableView;
}

- (SDCycleScrollView *)cycleScrollView
{
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,0,WIDTH,HEIGHT*0.3) delegate:nil placeholderImage:[UIImage imageNamed:@"placeholder"]];
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _cycleScrollView.delegate = self;
        _cycleScrollView.localizationImageNamesGroup = @[@"kWei_banner"];
        _cycleScrollView.pageDotColor = [UIColor whiteColor];
        _cycleScrollView.currentPageDotColor = DEFAULT_COLOR;
    }
    return _cycleScrollView;
}


- (CustNaviBarView *)naviBarView
{
    if (!_naviBarView) {
        _naviBarView = [[CustNaviBarView alloc] initWithFrame:CGRectMake(0,0,WIDTH,64)];
        _naviBarView.backgroundColor = [UIColor clearColor];
        WeakSelf(self);
        [_naviBarView setSearchBlock:^{
            ProductSearchViewController *search = [[ProductSearchViewController alloc] init];
            search.goodsStutas = YES;
            [weakself.navigationController pushForm:weakself.navigationController pushToAndHidden:search];
        }];
        
        [_naviBarView setLocationBlock:^{
            LocationServeViewController *locationVC = [[LocationServeViewController alloc] init];
            UINavigationController *locationServe = [[UINavigationController alloc] initWithRootViewController:locationVC];
            [weakself presentViewController:locationServe animated:false completion:nil];
        }];
    }
    return _naviBarView;
}


- (NSMutableArray<kWHomeModel *> *)bannerArray
{
    if (!_bannerArray) {
        _bannerArray = [[NSMutableArray alloc] init];
    }
    return _bannerArray;
}

- (NSMutableArray<kWCommonModel *> *)contentArray{
    if (!_contentArray) {
        _contentArray = [[NSMutableArray alloc] init];
    }
    return _contentArray;
}

- (NSMutableArray<kWHomeModel *> *)likeArray
{
    if (!_likeArray) {
        _likeArray = [NSMutableArray array];
    }
    return _likeArray;
}

@end
